home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 5 #8 / IMG 51 Vol 5-8.iso / Goodies / More For Your Games / Civ II / How to Create Custom Graphics / Ansel beta distribution / Scripts / Movie Making < prev    next >
Text File  |  1995-07-06  |  7KB  |  283 lines

  1. macro 'Make Movie to Disk…';
  2. {
  3. Captures images at a specified rate and saves them to disk.
  4. Select an area of interest within the Camera window before
  5. starting. Abort at any time by pressing the mouse button.
  6. }
  7. var
  8.   nFrames,n,Left,Top,Width,Height:integer;
  9.   interval,EndTicks,secs:integer;
  10.   FirstTime:boolean;
  11. begin
  12.   GetRoi(Left,Top,Width,Height);
  13.   if width=0 then begin
  14.      PutMessage('First select the area of interest in the Camera window.');
  15.      exit;
  16.   end;
  17.   nFrames:=GetNumber('Number of Frames?',10);
  18.   secs:=GetNumber ('Delay Between Frames (seconds)?',60.0);
  19.   interval:=round(secs*60);
  20.   FirstTime:=true;
  21.   for n:=1 to nFrames do begin
  22.      StopCapturing;  beep;
  23.      MakeRoi(Left,Top,Width,Height);
  24.      SaveAs('Frame ',n);
  25.      if FirstTime then begin
  26.         EndTicks:=TickCount+interval;
  27.         FirstTime:=false;
  28.      end;
  29.      if button then begin
  30.         StopCapturing;
  31.         exit;
  32.      end;
  33.      StartCapturing;
  34.      while TickCount<EndTicks do begin
  35.          secs:=(EndTicks-TickCount) div 60;
  36.          ShowMessage(n:1,'/',nFrames,' ',secs:4)
  37.      end;
  38.      EndTicks:=EndTicks+interval;
  39.   end;
  40.   StopCapturing;
  41. end;
  42.  
  43.  
  44. macro 'Make AV Time-lapse Movie…';
  45. {
  46. Captures a sequence of images to disk using the "Plug-in Digitizer"
  47. in "Faceless" mode. Abort by pressing the mouse button.
  48. }
  49. var
  50.   nFrames, n, pid:integer;
  51.   interval, StartTicks, EndTicks:integer;
  52.   time:real;
  53.   path:string;
  54. begin
  55.   Requiresversion(1.55);
  56.   SaveState;
  57.   path:=getString('Folder path:','hd400:movie');
  58.   nFrames:=GetNumber('Number of Frames?',10);
  59.   time:=GetNumber ('Delay Between Frames (seconds)?',60.0);
  60.   interval:=round(time*60);
  61.   StartTicks:=TickCount;
  62.   EndTicks:=TickCount+interval;
  63.   for n:=1 to nFrames do begin
  64.      time:=(TickCount-StartTicks)/ 60;
  65.      ShowMessage('frame: ', n:1,' \time: ',time:1:2);
  66.      Acquire('Plug-in Digitizer');
  67.      pid:=PidNumber;
  68.      SelectPic(pid);
  69.      SetForegroundColor(255);
  70.      SetFont('Monaco');
  71.      SetFontSize(9);
  72.      MoveTo(2,7);
  73.      write(n:3,'  ',time:4:2);
  74.      SaveAs(path,':Frame ',n);
  75.      while TickCount<EndTicks do begin
  76.         if button then exit;
  77.      end;
  78.      EndTicks:=EndTicks+interval;
  79.      Dispose;
  80.   end;
  81.   RestoreState;
  82. end;
  83.  
  84.  
  85. macro 'Capture Averaged to Stack…';
  86. var
  87.   x,y,i,s,f,t,width,height:integer;
  88.   camera, stack, avg, nFrames:integer;
  89. begin
  90.   nFrames:=GetNumber('Number of frames to capture:', 10);
  91.   SelectWindow('Camera');
  92.   camera:=PidNumber;
  93.   GetRoi(x,y,width,height);
  94.    if width=0 then begin
  95.     PutMessage('Rectangular selection required.');
  96.     exit;
  97.   end;
  98.   SetNewSize(width,height);
  99.   MakeNewStack('Stack');
  100.   stack:=PidNumber;
  101.   s:=TickCount;
  102.   for i:= 1 to nFrames do begin
  103.      ChoosePic(Camera);
  104.      MakeRoi(x,y,width,height);
  105.      AverageFrames;
  106.      RestoreRoi;
  107.      Copy;
  108.      ChoosePic(stack);
  109.      if i>1 then AddSlice;
  110.      Paste;
  111.   end;
  112.   f:=TickCount;
  113.   KillRoi;
  114.   SelectSlice(1);
  115.   t:=(f-s)/60;
  116.   ShowMessage('Time = ', t:1:2, ' seconds');
  117.   exit;
  118.   AverageSlices;
  119.   avg:=PidNumber;
  120.   SelectPic(stack);
  121.   Dispose;
  122.   SelectPic(avg);
  123. end;
  124.  
  125. procedure PlotFrameIntervals(nFrames: integer);
  126. var
  127.    xmin,xmax,ymin,ymax,i,xscale,yscale,yscale2:real;
  128.    width,height,margin,pwidth,pheight:integer;
  129.    x,y,pbottom,yinc:integer;
  130.    minInterval,maxInterval,offset:real;
  131.    interval,reqInterval,avgInterval,ElapsedTime:real;
  132.    TotalTime:real;
  133. begin
  134.   RequiresVersion(1.58);
  135.   SaveState;
  136.   margin:=40;
  137.   width:=500;
  138.   height:=300;
  139.   ymin:=999999;
  140.   ymax:=-999999;
  141.   ElapsedTime := PlotData[nFrames];
  142.   reqInterval := PlotData[nFrames+1];
  143.   avgInterval := ElapsedTime / (nFrames -1);
  144.   TotalTime := avgInterval * nFrames;
  145.   for i:=1 to nFrames -1 do begin
  146.       interval := PlotData[i+1]-PlotData[i];
  147.       if interval<ymin then ymin:=interval;
  148.       if interval>ymax then ymax:=interval;
  149.   end;
  150.   minInterval:=ymin;
  151.   maxInterval:=ymax;
  152.   ymin:=0;
  153.   xmin:=1;
  154.   xmax:=nFrames-1;
  155.   SetNewSize(width,height);
  156.   SetForeground(255);
  157.   SetBackground(0);
  158.   MakeNewWindow('Frame Intervals (seconds)');
  159.   pwidth:=width-margin-130;
  160.   pheight:=height-2*margin;
  161.   pbottom:=margin+pheight;
  162.   xscale:=pwidth/xmax;
  163.   yscale:=pheight/ymax;
  164.   yscale2:=pheight/(PlotData[nFrames]);
  165.   SetForeground(255);
  166.   SetBackground(0); 
  167.   SetLineWidth(1);
  168.   for i:=2 to nFrames do begin
  169.      interval := PlotData[i]-PlotData[i-1];
  170.      x:=margin+(i-1)*xscale;
  171.      y:=pbottom-interval*yscale;
  172.      MoveTo(x, pBottom);
  173.      LineTo(x,y);
  174.      MoveTo(margin+(i-2)*xscale, pBottom-(PlotData[i-1])*yscale2);
  175.      LineTo(margin+(i-1)*xscale, pBottom-(PlotData[i])*yscale2);
  176.   end;
  177.   KillRoi;
  178.   MoveTo(margin, margin);
  179.   LineTo(margin, margin+pheight);
  180.   LineTo(margin+pwidth, margin+pheight);
  181.   SetFont('Geneva');
  182.   SetFontSize(9);
  183.   SetText('Right Justified');
  184.   MoveTo(margin-2, margin+pheight-5);
  185.   writeln(ymin:1:3);
  186.   MoveTo(margin-2, margin);
  187.   writeln(ymax:1:3);
  188.   SetText('Left Justified');
  189.   x := margin+pwidth+10;
  190.   y := margin;
  191.   yinc := 12;
  192.   MoveTo(x, y);
  193.   writeln('frames=', nFrames:1);
  194.   y := y+yinc;
  195.   MoveTo(x, y);
  196.   writeln('expected time=', nFrames*reqInterval:1:4);
  197.   y := y+yinc;
  198.   MoveTo(x, y);
  199.   writeln('actual time=', TotalTime:1:4);
  200.   y := y+yinc;
  201.   MoveTo(x, y);
  202.   writeln('req. interval=', reqInterval:1:4);
  203.   y := y+yinc;
  204.   MoveTo(x, y);
  205.   writeln('avg interval=', avgInterval:1:4);
  206.   y := y+yinc;
  207.   MoveTo(x, y);
  208.   writeln('min interval=', minInterval:1:4);
  209.   y := y+yinc;
  210.   MoveTo(x, y);
  211.   writeln('max interval=', maxInterval:1:4);
  212.   y := y+yinc;
  213.   MoveTo(x, y);
  214.   if reqInterval <> 0.0 then
  215.      writeln('expected rate=', 1/reqInterval:1:3,' fps');
  216.   y := y+yinc;
  217.   MoveTo(x, y);
  218.   writeln('actual rate=', (nFrames)/TotalTime:1:3,' fps');
  219.  RestoreState;
  220. end;
  221.  
  222. macro 'Make Movie and Plot Intervals [M]';
  223. var
  224.   i, nFrames, x, y, w, h: integer;
  225.   avgInterval: real;
  226. begin
  227.   GetRoi(x, y, w, h);
  228.   if w = 0 then begin
  229.      PutMessage('Selection Required.');
  230.      exit;
  231.   end;
  232.   MakeMovie('dialog, time-stamp', -1, -1);
  233.   nFrames := PlotData[0];
  234.   PlotFrameIntervals(nFrames); 
  235. end;
  236.  
  237.  
  238. Macro 'Frame Rate vs. Frame Size';
  239. var
  240.   n, i, width, height,w,h:integer;
  241.   avgFrameInterval: real;
  242. begin
  243.    n := 50;
  244.    StartCapturing;
  245.    GetPicSize(width, height);
  246.    SetFont('Monaco');
  247.    SetFontSize(9);
  248.    NewTextWindow('Rate vs. Size', 150, 400);
  249.    MoveWindow(750, 50);
  250.    SaveState;
  251.    for i := 1 to n do begin
  252.      SelectWindow('Camera');
  253.      w := round(width*(i/n));
  254.       h := round(height*(i/n));
  255.       w := w - (w mod 4);
  256.       h := h - (h mod 4);
  257.      MakeRoi(0, 0, w, h);
  258.      MakeMovie('blind', 10, 0);
  259.      avgFrameInterval := GetSliceSpacing;
  260.      Dispose;
  261.      SelectWindow('Rate vs. Size');
  262.      writeln(i:3, avgFrameInterval:6:3, '  ', w:1:0, 'x', h:1:0 );
  263.   end;
  264.   RestoreState;
  265. end;
  266.  
  267.  
  268. macro 'Projection Example';
  269. begin
  270.    SetProjection('Initial Angle', 0);
  271.    SetProjection('Total Rotation', 360);
  272.    SetProjection('Rotation Increment', 30);
  273.    SetDensitySlice(0, 254);   {sets transparency bounds}
  274.    SetProjection('Surface Opacity', 50);
  275.    SetProjection('Surface Depth-Cueing', 50);
  276.    SetProjection('Interior Depth-Cueing', 50);
  277.    SetProjection('Save Projections', false);
  278.    SetProjection('Minimize Size', true);
  279.    SetProjection('Y-Axis');
  280.    SetProjection('Brightest Point');
  281.    Project; {Dialog is not displayed}
  282. end.
  283.